package com.yunhe.abnormal.service.data;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.yunhe.abnormal.domain.data.AbnormalEvent;
import com.yunhe.abnormal.domain.data.AlarmEvent;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.model.PageParam;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface AbnormalEventService {

    AbnormalEvent create(AbnormalEvent abnormalEvent) throws ObjectNotFoundException, JsonProcessingException;

    AbnormalEvent createForHistory(AbnormalEvent abnormalEvent) throws ObjectNotFoundException, JsonProcessingException;

    Iterable<AbnormalEvent> create(List<AbnormalEvent> abnormalEvents) throws ObjectNotFoundException, JsonProcessingException;

    void delete(Long id);

    AbnormalEvent update(AbnormalEvent abnormalEvent) throws ObjectNotFoundException;

    AbnormalEvent update(Long id,
                         Optional<Long> stationId,
                         Optional<Long> deviceId,
                         Optional<Long> abnormalRuleId,
                         Optional<Long> userIdProcess,
                         Optional<Long> abnormalStatusId,
                         Optional<Long> alarmLevelId,
                         Optional<String> latestProcessTime) throws ObjectNotFoundException;

    AbnormalEvent findById(Long id);

    Iterable<AbnormalEvent> retrieve(Optional<List<Long>> stationIds,
                                     Optional<List<Long>> devId,
                                     Optional<Long> abnormalRuleId,
                                     Optional<List<Long>> abnormalStatusIds,
                                     Optional<List<Long>> alarmLevelIds,
                                     Optional<String> dtime,
                                     Optional<String> queryStr,
                                     PageParam pageParam);

    List<AbnormalEvent> findByAbnormalRuleIdAndAlarmLevelIdAndStatusId(Long abnormalRuleId, Long alarmLevelId, Long abnormalStatusId);

    void clearAbnormalEventByAlarmEventId(AlarmEvent alarmEvent) throws ObjectNotFoundException;

    Map<String, List<AbnormalEvent>> getHistoryEventMap();

    String generateKey(Long abnormalRuleId, Long alarmLevelId);
}
